import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_elf/utils/print_utils.dart';

class WebViewTeState extends StatefulWidget {
  String url;
  WebViewTeState({this.url});
  @override
  __WebViewTeStateState createState() => new __WebViewTeStateState();
}

///https://v.qq.com/x/cover/dh1fyeb58mn9mqt.html
///http://at520.cn/jx/?url=
///http://api.nobij.top/jx/?url=
///http://17kyun.com/api.php?url=
class __WebViewTeStateState extends State<WebViewTeState> {
  String s1 = 'http://at520.cn/jx/?url=';
  String s2 = 'http://api.nobij.top/jx/?url=';
  String s3 = 'http://17kyun.com/api.php?url=';
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    globalPrint("=============="+widget.url);
  }

  WebViewController _webViewController;
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: WebView(
        onPageFinished: (_){
//          _webViewController.loadUrl("javascript:{document.getElementById('movie-text').value='http://mv.688ing.com'}");
//          _webViewController.evaluateJavascript("javascript:document.getElementById('movie-text').value='https://v.qq.com/x/cover/dh1fyeb58mn9mqt.html'");
//          _webViewController.evaluateJavascript("javascript:document.getElementById('movie-btn').click();");
        },
        initialUrl:'http://www.baidu.com',
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _webViewController = webViewController;
//          _webViewController.loadUrl("javascript:document.getElementsByClassName('input-lg')[0].value='Hello'");
//          _webViewController.evaluateJavascript("javascript:document.getElementsByClassName('input-lg')[1].value='Hello'");
//          _webViewController.evaluateJavascript("javascript:document.getElementsByClassName('input-lg')[2].value='Hello'");
//          _webViewController.evaluateJavascript("javascript:document.getElementsByClassName('input-lg')[0].value='Hello'");
//          _webViewController.evaluateJavascript("javascript:document.getElementsByClassName('input-lg')[1].value='Hello'");
//          _webViewController.evaluateJavascript("javascript:document.getElementsByClassName('input-lg')[2].value='Hello'");
//          _webViewController
//              ?.evaluateJavascript('callJS("visible")')
//              ?.then((result) {
//            // You can handle JS result here.
//          });
        },
        // TODO(iskakaushik): Remove this when collection literals makes it to stable.
        // ignore: prefer_collection_literals
      )
    );
  }
}